home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: Unable to check calloc`s
- Date: 08 Feb 1996 15:37:25 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb8083725@qcd.lanl.gov>
- References: <4f2l8a$c98@gail.ripco.com> <4fadmp$t6g@osage.csc.ti.com>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: ramli@sislnews.csc.ti.com's message of 7 Feb 1996 08:41:29 -0600
-
- In article <4fadmp$t6g@osage.csc.ti.com> ramli@sislnews.csc.ti.com
- (C. S. Ramalingam) writes:
- <snip>
- When would using calloc be more appropriate than using malloc ? Is it true
- that the only use for calloc is in initializing integral values to zero ?
-
- Yes. calloc will always initialize its region to all bits zero ... but
- if that region is not of integral type (e.g. if it is a pointer or a
- float), it can give access errors if accessed without further
- initialization because `all bits zero' may not be a valid bit
- pattern. Technically, I believe, because of interpretations that allow
- integral types to have holes which require to be fixed at some value,
- calloc may not be, strictly speaking, portable even for integral
- types: but I would usually not worry about things like that. The only
- place where I am absolutely sure that calloc does initialize to a
- known value, rather than a known possibly invalid bitpattern, is when
- initializing an array of character types.
-
- If so, why was a new function, which appears to have very limited used,
- introduced in the first place ?
-
- I would guess out of historical necessity. calloc is very rarely
- needed in portable code: it is best to avoid it.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-